#define _CRT_SECURE_NO_WARNINGS 1
#include"game.h"
//初始化棋盘
void InitBoard(char board[ROWS][COLS], int rows, int cols, char ret)
{
	for (int i = 0; i < rows; i++)

	{
		for (int j = 0; j < cols; j++)
		{
			board[i][j] = ret;
		}
	}
}
//打印棋盘
void PrintBoard(char board[ROWS][COLS], int row, int col)
{
	printf("---------扫雷---------\n");
	for (int i = 0; i <= 9; i++)
	{
		printf("%d ", i);
	}
	printf("\n");

	for (int i = 1; i <= row; i++)
	{
		printf("%d ",i);
		for (int j = 1; j <= col; j++)
		{
			printf("%c ", board[i][j]);
		}
		printf("\n");
	}
}
//随机产生10个雷的不同位置坐标，布置在Mine棋盘上
void SetMine(char board[ROWS][COLS],int row,int col)
{
	int x = 0;
	int y = 0;
	int count = 0;
	while (count < MineCount)
	{
		x = rand() % row + 1;
		y = rand() % col + 1;
		if (board[x][y] != '1')
		{
			count++;
			board[x][y] = '1';
		}
	}
}

//排查雷
void SweepMine(char Mine[ROWS][COLS], char Show[ROWS][COLS],int row,int col)
{
	int x = 0;
	int y = 0;
	int AroundMineCount = 0;
	int num = 0;
	while (num<row*col-MineCount)
	{
		scanf("%d %d", &x, &y);
		if (x >= 1 && x <= row && y >= 1 && y <= col)
		{
			if (Mine[x][y] == '1')

			{
				printf("很遗憾，你踩雷了！\n");
				printf("下方为 雷 的位置图\n");
				PrintBoard(Mine, ROW, COL);
				break;
			 }
			else
			{
				num++;
				AroundMineCount = Mine[x - 1][y - 1]
					+ Mine[x - 1][y]
					+ Mine[x - 1][y + 1]
					+ Mine[x][y - 1]
					+ Mine[x][y]
					+ Mine[x][y + 1]
					+ Mine[x + 1][y - 1]
					+ Mine[x + 1][y]
					+ Mine[x + 1][y + 1] - 9 * '0';
				Show[x][y] = AroundMineCount + '0';
				PrintBoard(Show, ROW, COL);
			}

		}
		else
		{
			printf("输入错误，请重新输入 x/y(0~9)\n");
		}
	}
	if (num == row * col - MineCount)

	{
		printf("恭喜你，排查出了所有雷\n");
	}

	
}

